import {fileURLToPath, URL} from 'node:url'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'
import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// https://vite.dev/config/
export default defineConfig({
    server: {
        host: "0.0.0.0", // 允许所有 IP 访问
        // proxy: {
        //   "/api": {
        //     target: "http://100.0.4.122:9880",
        //     changeOrigin: true,
        //     rewrite: (path) => path.replace(/^\/api/, ""),
        //   },
        // },
        port: 9001, // 确保端口未被占用
        hmr: {
            clientPort: 9001, // 解决 HMR 热更新问题
        },
    },
    plugins: [
        vue(),
        vueDevTools(),
        AutoImport({
            resolvers: [ElementPlusResolver()],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
        }),
    ],

    css: {
        preprocessorOptions: {
            scss: {
                additionalData: `@import "@/scss/variable.scss";`, // 例如，导入全局变量文件
            },
        },
    },
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        },
    },
})
